namespace Pigg.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Start : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.AuthPermission",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.AuthRole",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.People",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Email = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ContentItem",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Key = c.String(nullable: false, maxLength: 255),
                        ItemType = c.String(nullable: false, maxLength: 255),
                        Value = c.String(),
                        PageContent_Id = c.Int(),
                        ContentList_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ContentPage", t => t.PageContent_Id)
                .ForeignKey("dbo.ContentList", t => t.ContentList_Id)
                .Index(t => t.PageContent_Id)
                .Index(t => t.ContentList_Id);
            
            CreateTable(
                "dbo.ContentPage",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ParentId = c.Int(),
                        CultureCode = c.String(nullable: false, maxLength: 20),
                        Title = c.String(nullable: false, maxLength: 255),
                        Description = c.String(),
                        UrlAlias = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ContentList",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CultureCode = c.String(nullable: false, maxLength: 20),
                        Key = c.String(nullable: false, maxLength: 20),
                        PageContent_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ContentPage", t => t.PageContent_Id)
                .Index(t => t.PageContent_Id);
            
            CreateTable(
                "dbo.ImageContent",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CultureCode = c.String(nullable: false, maxLength: 20),
                        Path = c.String(nullable: false, maxLength: 255),
                        Description = c.String(),
                        ContentPage_Id = c.Int(),
                        ImageList_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ContentPage", t => t.ContentPage_Id)
                .ForeignKey("dbo.ImageList", t => t.ImageList_Id)
                .Index(t => t.ContentPage_Id)
                .Index(t => t.ImageList_Id);
            
            CreateTable(
                "dbo.ImageList",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CultureCode = c.String(nullable: false, maxLength: 20),
                        Name = c.String(nullable: false, maxLength: 255),
                        Description = c.String(),
                        ContentPage_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ContentPage", t => t.ContentPage_Id)
                .Index(t => t.ContentPage_Id);
            
            CreateTable(
                "dbo.MenuContainer",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ParentId = c.Int(),
                        CultureCode = c.String(nullable: false, maxLength: 20),
                        Name = c.String(nullable: false, maxLength: 255),
                        Order = c.Decimal(nullable: false, precision: 18, scale: 2),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.MenuItem",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(nullable: false, maxLength: 255),
                        Url = c.String(nullable: false, maxLength: 20),
                        Order = c.Decimal(nullable: false, precision: 18, scale: 2),
                        TemplateUrl = c.String(nullable: false, maxLength: 255),
                        Content = c.String(),
                        MenuContainer_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.MenuContainer", t => t.MenuContainer_Id)
                .Index(t => t.MenuContainer_Id);
            
            CreateTable(
                "dbo.AuthRoleAuthPermission",
                c => new
                    {
                        AuthRole_Id = c.Int(nullable: false),
                        AuthPermission_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.AuthRole_Id, t.AuthPermission_Id })
                .ForeignKey("dbo.AuthRole", t => t.AuthRole_Id, cascadeDelete: true)
                .ForeignKey("dbo.AuthPermission", t => t.AuthPermission_Id, cascadeDelete: true)
                .Index(t => t.AuthRole_Id)
                .Index(t => t.AuthPermission_Id);
            
            CreateTable(
                "dbo.PersonAuthPermission",
                c => new
                    {
                        Person_Id = c.Int(nullable: false),
                        AuthPermission_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Person_Id, t.AuthPermission_Id })
                .ForeignKey("dbo.People", t => t.Person_Id, cascadeDelete: true)
                .ForeignKey("dbo.AuthPermission", t => t.AuthPermission_Id, cascadeDelete: true)
                .Index(t => t.Person_Id)
                .Index(t => t.AuthPermission_Id);
            
            CreateTable(
                "dbo.PersonAuthRole",
                c => new
                    {
                        Person_Id = c.Int(nullable: false),
                        AuthRole_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Person_Id, t.AuthRole_Id })
                .ForeignKey("dbo.People", t => t.Person_Id, cascadeDelete: true)
                .ForeignKey("dbo.AuthRole", t => t.AuthRole_Id, cascadeDelete: true)
                .Index(t => t.Person_Id)
                .Index(t => t.AuthRole_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.MenuItem", "MenuContainer_Id", "dbo.MenuContainer");
            DropForeignKey("dbo.ImageList", "ContentPage_Id", "dbo.ContentPage");
            DropForeignKey("dbo.ImageContent", "ImageList_Id", "dbo.ImageList");
            DropForeignKey("dbo.ImageContent", "ContentPage_Id", "dbo.ContentPage");
            DropForeignKey("dbo.ContentList", "PageContent_Id", "dbo.ContentPage");
            DropForeignKey("dbo.ContentItem", "ContentList_Id", "dbo.ContentList");
            DropForeignKey("dbo.ContentItem", "PageContent_Id", "dbo.ContentPage");
            DropForeignKey("dbo.PersonAuthRole", "AuthRole_Id", "dbo.AuthRole");
            DropForeignKey("dbo.PersonAuthRole", "Person_Id", "dbo.People");
            DropForeignKey("dbo.PersonAuthPermission", "AuthPermission_Id", "dbo.AuthPermission");
            DropForeignKey("dbo.PersonAuthPermission", "Person_Id", "dbo.People");
            DropForeignKey("dbo.AuthRoleAuthPermission", "AuthPermission_Id", "dbo.AuthPermission");
            DropForeignKey("dbo.AuthRoleAuthPermission", "AuthRole_Id", "dbo.AuthRole");
            DropIndex("dbo.MenuItem", new[] { "MenuContainer_Id" });
            DropIndex("dbo.ImageList", new[] { "ContentPage_Id" });
            DropIndex("dbo.ImageContent", new[] { "ImageList_Id" });
            DropIndex("dbo.ImageContent", new[] { "ContentPage_Id" });
            DropIndex("dbo.ContentList", new[] { "PageContent_Id" });
            DropIndex("dbo.ContentItem", new[] { "ContentList_Id" });
            DropIndex("dbo.ContentItem", new[] { "PageContent_Id" });
            DropIndex("dbo.PersonAuthRole", new[] { "AuthRole_Id" });
            DropIndex("dbo.PersonAuthRole", new[] { "Person_Id" });
            DropIndex("dbo.PersonAuthPermission", new[] { "AuthPermission_Id" });
            DropIndex("dbo.PersonAuthPermission", new[] { "Person_Id" });
            DropIndex("dbo.AuthRoleAuthPermission", new[] { "AuthPermission_Id" });
            DropIndex("dbo.AuthRoleAuthPermission", new[] { "AuthRole_Id" });
            DropTable("dbo.PersonAuthRole");
            DropTable("dbo.PersonAuthPermission");
            DropTable("dbo.AuthRoleAuthPermission");
            DropTable("dbo.MenuItem");
            DropTable("dbo.MenuContainer");
            DropTable("dbo.ImageList");
            DropTable("dbo.ImageContent");
            DropTable("dbo.ContentList");
            DropTable("dbo.ContentPage");
            DropTable("dbo.ContentItem");
            DropTable("dbo.People");
            DropTable("dbo.AuthRole");
            DropTable("dbo.AuthPermission");
        }
    }
}
